package com.xukai.springboot.config;

import com.xukai.springboot.filter.SecurityFilter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;

@Configuration
public class ApplicationConfiguration {

    /**
     * 站点状态
     */
    @Value("${isDebug}")
    private String isDebug;

    @Bean
    public FilterRegistrationBean testFilterRegistration() {


        FilterRegistrationBean registration = new FilterRegistrationBean();


        registration.setFilter(securityFilter());

        registration.addUrlPatterns("/api/*");
        registration.addInitParameter("paramName", "paramValue");
        registration.setName("testFilter");
        registration.setOrder(1);
        return registration;
    }

    @Bean
    public Filter securityFilter() {
        SecurityFilter securityFilter = new SecurityFilter();
        securityFilter.setIsDebug(Integer.valueOf(isDebug));
        securityFilter.getPatterns().add("/createuser");
        securityFilter.getPatterns().add("/login");
        return securityFilter;
    }
}
